To explore different scenarios for furture installation projections of PV (or any technology), ReEDS output data can be useful in providing standard scenarios. ReEDS installation projections are used in this journal as input data to the PV ICE tool.
Current sections include:
import numpy as np
import pandas as pd
import os,sys
import matplotlib.pyplot as plt
plt.rcParams.update({'font.size': 22})
plt.rcParams['figure.figsize'] = (12, 8)
import os
from pathlib import Path
testfolder = str(Path().resolve().parent.parent.parent / 'PV_ICE' / 'TEMP')
print ("Your simulation will be stored in %s" % testfolder)
reedsFile = str(Path().resolve().parent.parent.parent / 'PV_ICE' / 'baselines' / 'SupportingMaterial' / 'December Core Scenarios ReEDS Outputs Solar Futures v3a.xlsx')
print ("Input file is stored in %s" % reedsFile)
=======
reedsFile = str(Path().resolve().parent.parent.parent / 'PV_ICE' / 'baselines' / 'SupportingMaterial' / 'December Core Scenarios ReEDS Outputs Solar Futures v3a.xlsx')
print ("Input file is stored in %s" % reedsFile)
>>>>>>> be4860f9b4c2ce5a2b887e2d153f7cfea32b3a6c:docs/tutorials/Solar Futures Simulations/(development) ReEDS Scenarios Baseline Creation.html
Input file is stored in C:\Users\sayala\Documents\GitHub\PV_ICE\PV_ICE\baselines\SupportingMaterial\December Core Scenarios ReEDS Outputs Solar Futures v3a.xlsx
REEDSInput = pd.read_excel(reedsFile,
# sheet_name="new installs PV (2)")
sheet_name="new installs PV")
#index_col=[0,2,3]) #this casts scenario, PCA and State as levels
rawdf = REEDSInput.copy()
rawdf.drop(columns=['State'], inplace=True)
rawdf.drop(columns=['Tech'], inplace=True) #tech=pvtotal from "new installs PV sheet", so can drop
rawdf.set_index(['Scenario','Year','PCA'], inplace=True)
rawdf.head(21)
import PV_ICE
r1 = PV_ICE.Simulation(name='Simulation1', path=testfolder)
r1.createScenario(name='US', massmodulefile=r'..\baselines\baseline_modules_mass_US.csv')
r1.scenMod_noCircularity() # Reeds Solar Future Study had circularity paths set to 0
baseline = r1.scenario['US'].dataIn_m
baseline = baseline.drop(columns=['new_Installed_Capacity_[MW]'])
baseline.set_index('year', inplace=True)
baseline.index = pd.PeriodIndex(baseline.index, freq='A') # A -- Annual
baseline.head()
# Set header dynamically
import csv
massmodulefile=r'..\baselines\baseline_modules_mass_US.csv'
with open(massmodulefile, newline='') as f:
reader = csv.reader(f)
row1 = next(reader) # gets the first line
row2 = next(reader) # gets the first line
row11 = 'year'
for x in row1[1:]:
row11 = row11 + ',' + x
row22 = 'year'
for x in row2[1:]:
row22 = row22 + ',' + x
row11
for ii in range (len(rawdf.unstack(level=1))):
PCA = rawdf.unstack(level=1).iloc[ii].name[1]
SCEN = rawdf.unstack(level=1).iloc[ii].name[0]
SCEN=SCEN.replace('+', '_')
filetitle = SCEN+'_'+PCA +'.csv'
subtestfolder = os.path.join(testfolder, 'PCAs')
if not os.path.exists(subtestfolder):
os.makedirs(subtestfolder)
filetitle = os.path.join(subtestfolder, filetitle)
A = rawdf.unstack(level=1).iloc[ii]
A = A.droplevel(level=0)
A.name = 'new_Installed_Capacity_[MW]'
A = pd.DataFrame(A)
A.index=pd.PeriodIndex(A.index, freq='A')
A = pd.DataFrame(A)
A['new_Installed_Capacity_[MW]'] = A['new_Installed_Capacity_[MW]'] * 0.85
A['new_Installed_Capacity_[MW]'] = A['new_Installed_Capacity_[MW]'] * 1000 # ReEDS file is in GW.
# Add other columns
A = pd.concat([A, baseline.reindex(A.index)], axis=1)
header = row11 + '\n' + row22 + '\n'
with open(filetitle, 'w', newline='') as ict:
# Write the header lines, including the index variable for
# the last one if you're letting Pandas produce that for you.
# (see above).
for line in header:
ict.write(line)
# savedata.to_csv(ict, index=False)
A.to_csv(ict, header=False)
rawdf = REEDSInput.copy()
#rawdf.drop(columns=['State'], inplace=True)
rawdf.drop(columns=['Tech'], inplace=True)
rawdf.set_index(['Scenario','Year','PCA', 'State'], inplace=True)
rawdf.head(21)
#df = rawdf.groupby(['Scenario','State', 'Year'])['Capacity (GW)'].sum(axis=0)
df = rawdf.groupby(['Scenario','State', 'Year'])['Capacity (GW)'].sum()
df = pd.DataFrame(df)
df.head()
for ii in range (len(df.unstack(level=2))):
STATE = df.unstack(level=2).iloc[ii].name[1]
SCEN = df.unstack(level=2).iloc[ii].name[0]
SCEN=SCEN.replace('+', '_')
filetitle = SCEN+'_'+STATE +'.csv'
subtestfolder = os.path.join(testfolder, 'STATEs')
if not os.path.exists(subtestfolder):
os.makedirs(subtestfolder)
filetitle = os.path.join(subtestfolder, filetitle)
A = df.unstack(level=2).iloc[ii]
A = A.droplevel(level=0)
A.name = 'new_Installed_Capacity_[MW]'
A = pd.DataFrame(A)
A.index=pd.PeriodIndex(A.index, freq='A')
A = pd.DataFrame(A)
A['new_Installed_Capacity_[MW]'] = A['new_Installed_Capacity_[MW]'] * 0.85 # marketshares['Si']
A['new_Installed_Capacity_[MW]'] = A['new_Installed_Capacity_[MW]'] * 1000 # ReEDS file is in GW.
# Add other columns
A = pd.concat([A, baseline.reindex(A.index)], axis=1)
header = row11 + '\n' + row22 + '\n'
with open(filetitle, 'w', newline='') as ict:
# Write the header lines, including the index variable for
# the last one if you're letting Pandas produce that for you.
# (see above).
for line in header:
ict.write(line)
# savedata.to_csv(ict, index=False)
A.to_csv(ict, header=False)
rawdf = REEDSInput.copy()
#rawdf.drop(columns=['State'], inplace=True)
rawdf.drop(columns=['Tech'], inplace=True)
rawdf.set_index(['Scenario','Year'], inplace=True)
rawdf.head(21)
#df = rawdf.groupby(['Scenario','Year'])['Capacity (GW)'].sum(axis=0)
df = rawdf.groupby(['Scenario','Year'])['Capacity (GW)'].sum()
import PV_ICE
r1 = PV_ICE.Simulation(name='Simulation1', path=testfolder)
r1.createScenario(name='US', massmodulefile=r'..\baselines\baseline_modules_mass_US.csv')
r1.scenMod_noCircularity() # Reeds Solar Future Study had circularity paths set to 0
r1.scenario['US'].dataIn_m['mod_EOL_collection_eff'] = 0.0
baseline = r1.scenario['US'].dataIn_m
baseline = baseline.drop(columns=['new_Installed_Capacity_[MW]'])
baseline.set_index('year', inplace=True)
baseline.index = pd.PeriodIndex(baseline.index, freq='A') # A -- Annual
baseline.head()
for ii in range (len(df.unstack(level=1))):
SCEN = df.unstack(level=1).index[ii]
SCEN=SCEN.replace('+', '_')
filetitle = SCEN+'.csv'
subtestfolder = os.path.join(testfolder, 'USA')
if not os.path.exists(subtestfolder):
os.makedirs(subtestfolder)
filetitle = os.path.join(subtestfolder, filetitle)
A = df.unstack(level=1).iloc[ii]
A.name = 'new_Installed_Capacity_[MW]'
A = pd.DataFrame(A)
A.index=pd.PeriodIndex(A.index, freq='A')
A = pd.DataFrame(A)
A['new_Installed_Capacity_[MW]'] = A['new_Installed_Capacity_[MW]'] * 0.85 # marketshares['Si']
A['new_Installed_Capacity_[MW]'] = A['new_Installed_Capacity_[MW]'] * 1000 # ReEDS file is in GW.
# Add other columns
A = pd.concat([A, baseline.reindex(A.index)], axis=1)
header = row11 + '\n' + row22 + '\n'
with open(filetitle, 'w', newline='') as ict:
# Write the header lines, including the index variable for
# the last one if you're letting Pandas produce that for you.
# (see above).
for line in header:
ict.write(line)
# savedata.to_csv(ict, index=False)
A.to_csv(ict, header=False)